package com.iris.live.services.data.repositories;

import com.iris.live.services.data.models.Lsh保险公司设置Model;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by sxy on 2016/7/11.
 */
public interface Lsh保险公司设置Repository extends JpaRepository<Lsh保险公司设置Model, Integer>, JpaSpecificationExecutor<Lsh保险公司设置Model> {


    @Query("select u.保险公司编号 from Lsh保险公司设置Model u where u.保险公司=?1 and u.启用状态 = '启用'")
    Integer findByinsName(String name);

    @Query("select u from Lsh保险公司设置Model u where u.启用状态='启用'")
    List<Lsh保险公司设置Model> findAllCompanyByEnable();

    @Query(value = "select u.* from lsh保险公司设置 u  JOIN lsh保险公司使用 a ON  a.保险公司编号=u.保险公司编号 AND a.许可=?2 where u.启用状态 = '启用' AND a.使用状态='启用' " +
            " and LOCATE(brand, ?1) > 0 and ( area_id = (select parent_id from group_area where permit = ?2 ) OR area_id IS NULL )",nativeQuery = true)
    List<Lsh保险公司设置Model> getInsuranceCompanyByBrand(String brand,String permit);

}
